<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
	<head>
		<title>tie</title>
        <style type='text/css'>
            body {font-family: verdana}
            .error {border: solid 1px red;}
            .error_text { color: red; font-size: 10px;}
            td {padding: 3px;}
			
			#sliderWrapper {
				border: solid 1px gray;
				width: 300px;
				height: 30px;
			}
			.mxui_slider {
				width: 30px;
				height: 30px;
				background-color: green;
			}
			.rating .selected {
				font-size: 20px;
				font-weight: bold;
				color: red;
			}
        </style>
	</head>
	<body>
		
		<div id='sliderWrapper'><div id='age1'></div></div>
		<div id='rating'></div>
		<input type='text' id='age2' />

		<textarea id='age3'></textarea>
		
		
		<select id='age4'>
			<option value='1'>1</option>
			<option value='2'>2</option>
			<option value='3'>3</option>
			<option value='4'>4</option>
			<option value='5'>5</option>
			<option value='6'>6</option>
			<option value='7'>7</option>
			<option value='8'>8</option>
			<option value='9'>9</option>
			<option value='10'>10</option>
		</select>
		
		
		<script type='text/javascript' 
                src='../../steal/steal.js'>   
			steal('jquery/model','jquery/tie','mxui/slider').then(function(){
			
			$.Model.extend("Person",{
				init : function(){
					this.validateFormatOf(["email"], /\w+\@\w+\.(com|net)/, "not a valid email")
					this.validate("birthday",function(){
						if(this.birthday > new Date){
							return "your birthday needs to be in the past"
						}
					})
				}
			},{
				setAge : function(age, success, error){
					age =  +(age);
					if(isNaN(age) || !isFinite(age) || age < 1 || age > 10){
						error()
					}else{
						$.ajax({
							url: "/update/age",
							data: {
								age: age
							},
							success: success,
							error: error
						})
					}
				}
			});
			$.Controller.extend("Rating",{
				init : function(){
					var html = [];
					for(var i =0; i < 15; i++){
						html.push("<a href='javascript://'>"+(i+1)+".</a>")
					}
					this.element.html(html.join(" "))
				},
				val : function(num){
					var selected = this.element.find(".selected");
					if(num){
						selected.removeClass("selected");
						this.element.find("a").eq(num-1)
							.addClass("selected")
					}else{
						return selected.text();
					}
				},
				"a click" : function(el){
					this.element.find(".selected").removeClass('selected');
					el.addClass('selected');
					this.element.trigger("change",el.text())
				}
			})
			
			person = new Person({age: 1});
			$("#age1").mxui_slider({interval: 1, min: 1, max: 10});
			$("#rating").rating();
			$("#age1, #age2, #age3, #age4, #rating").tie(person,"age")
			})
		</script>
	</body>
</html>